package org.developer.study.springboot.service;

import org.developer.study.springboot.dao.CustomerRepository;
import org.developer.study.springboot.entity.TInfo;
import org.developer.study.springboot.exception.BizServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2017/1/27.
 */
@Service
@Transactional
public class DemoService {
    @Autowired
    private CustomerRepository customerRepository;

    public void demo() {
        throw new BizServiceException("biz run error");
    }

    public TInfo findSpecifyInfo(Long id) {
        saveInfo(); //同一事物保持后不能马上查询到，saveInfo于findOne不同事物那么执行saveInfo就里面commit也就是说下面findOne可以查询到保存的值
        return  customerRepository.findOne(id);//saveInfo于findOne是在同一个类中，可以认为是同一个事物，一起提交一起回滚
    }

    public TInfo saveInfo() {
        TInfo tInfo = new TInfo();
        tInfo.settUserName("developer");
        tInfo.settUserAge(23+"");
        return  customerRepository.save(tInfo);
    }

}
